package team.cdlzz.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author zw
 * @date 2022-06-19.
 */
@Configuration( proxyBeanMethods = false) //全局配置类
public class WebConfig extends WebMvcConfigurerAdapter { //继承一个运行跨域访问的类
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**") //允许任意的请求信息
//                .allowCredentials(true) //允许携带信息
//                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
//                .allowedOrigins("http://localhost:8080","http://192.168.137.111:8080","null") //开放接收的端口
//                //全局开放所有端口
////                .allowedOriginPatterns("*")
//                .maxAge(3000); //最高延时时间 3妙

        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedOriginPatterns("*")
                .allowedMethods("*");
   }
}
